﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

/**
 * 创建时间：2014/11/15 20:49:18
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace WCYCReader.Utility
{
    public sealed class Helper
    {
        /// <summary>
        /// 16进制转argb颜色
        /// <para>#c1dc23写成#ffc1dc23，其中前两位ff是透明度</para>
        /// </summary>
        /// <param name="colorName"></param>
        /// <returns></returns>
        public static Color HexToColor(string colorName)
        {
            if (colorName.StartsWith("#"))
                colorName = colorName.Replace("#", string.Empty);
            int v = int.Parse(colorName, System.Globalization.NumberStyles.HexNumber);
            return new Color()
            {
                A = Convert.ToByte((v >> 24) & 255),
                R = Convert.ToByte((v >> 16) & 255),
                G = Convert.ToByte((v >> 8) & 255),
                B = Convert.ToByte((v >> 0) & 255)
            };
        }
    }
}